package com.monitor.log.biz.core;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.core.NamedThreadLocal;
import org.springframework.core.env.Environment;

import com.system.comm.utils.FrameSpringBeanUtil;
import com.system.comm.utils.FrameStringUtil;
import com.system.comm.utils.FrameTimeUtil;

public class BizLogData {

	public static final String HTTP_PATH = "http.path";
	public static final String HTTP_URL = "http.url";
	public static final String HTTP_REMOTE_ADDR = "http.remoteAddr";
	public static final String HTTP_SERVICE_ID = "http.serviceId";
	public static final String HTTP_PARAMS = "http.params";
	public static final String HTTP_REQUEST_TIME = "http.request.time";
	public static final String HTTP_RESPONSE = "http.response";
	public static final String HTTP_RESPONSE_TIME = "http.response.time";
	/**
	 * 日志模块加载时间
	 */
	private static Date startTime = new Date();
	public static boolean isDelaySave = false;
	/**
	 * 添加排除采集日志的接口地址
	 * @param urls
	 */
	public static List<String> getExcludeUrl() {
		Environment env = FrameSpringBeanUtil.getBean(Environment.class);
		String excludeUrl = env.getProperty("save.log.exclude.url");
		if (FrameStringUtil.isEmpty(excludeUrl)) {
			return new ArrayList<>();
		}
		return FrameStringUtil.toArray(excludeUrl, ",");
	}
	/**
	 * 延迟保存
	 * @return
	 */
	public static boolean isDelaySave() {
		if (!isDelaySave) {
			long diff = FrameTimeUtil.getDateDiff(startTime, FrameTimeUtil.getTime(), 0);
			if (diff > 5) {
				isDelaySave = true;
			}
		}
		return isDelaySave;
	}

	public static final String MS_TRACE_ID = "msTraceId";

	private static final ThreadLocal<Long> ZUUL_REQ_TIME_TL = new NamedThreadLocal<Long>("ThreadLocal zuul req time");
	public static Long getZuulReqTime() {
		return ZUUL_REQ_TIME_TL.get();
	}
	public static void setZuulReqTime(Long zuulReqTime) {
		ZUUL_REQ_TIME_TL.set(zuulReqTime);
	}

}
